const execfunc = function(func, input, config){
    var output = func(input, config);
    return {output: output, config: config};
}
const atob = function(data){
    var dict = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
    var _0x14a9e2 = String(data).replace(/=+$/, '');
    for (var i = 0x0, _0x437741, _0x3165e4, _0x8ba7ac = 0x0, _0x37510f = ''; _0x3165e4 = _0x14a9e2['charAt'](_0x8ba7ac++); ~_0x3165e4 && (_0x437741 = i % 0x4 ? _0x437741 * 0x40 + _0x3165e4 : _0x3165e4,
    i++ % 0x4) ? _0x37510f += String['fromCharCode'](0xff & _0x437741 >> (-0x2 * i & 0x6)) : 0x0) {
        _0x3165e4 = dict['indexOf'](_0x3165e4);
    }
    return _0x37510f;
}
var window = {
    atob: atob
};

const loadClass = function( className ){
    return eval("Packages.com.jin.webvideo.js.loadClass."  + className);
}

const URLUtil = loadClass("URLUtil");
const console = (function(){
    var Console = loadClass("Console");
    return {
        log: function(content){
            if (typeof content === "object"){
                content = JSON.stringify(content);
            }
            Console.log(content);
        }
    }
})();
var RequestSender = function(){
    var sender = loadClass('HttpSender');
    var URL = loadClass('URLBuilder')
    function isNull(o){
        return o === undefined || o === null;
    }
    function obj2QueryStr( o ){
        var queryStr = "";
        if (typeof o === 'string'){
            return o;
        }
        if (typeof o !== 'object'){
            return queryStr;
        }
        for ( var k in o ){
            queryStr += "&" + k + "=" + o[k];
        }
        if (queryStr.length > 0){
            return queryStr.substring(1);
        }
        return queryStr;
    }
    function dataParser(rst){
        rst = JSON.parse(rst);
        // 失败
        if (rst.code == 0){
            throw rst.msg;
        }
        return rst.data;
    }
    // processData true转化为查询字符串
    var get = function(url, data, header){
        if (isNull(header)){
            header = {};
        }
        if (isNull(data)){
            data = "";
        }
        var query = obj2QueryStr(data);
        var _url = new URL(url);
        if (_url.getQuery()!=null && _url.getQuery().length != 0){
            if (!_url.getQuery().endsWith("&")){
                query = "&" + query;
            }
            query = _url.getQuery() + query;
        }
        _url.setQuery(query);
        url = _url.toString();
        console.log(url);
        return dataParser(sender.get(url, obj2QueryStr(header)));
    }
    var post = function(url, data, processData, header){
        if (isNull(processData)){
            processData = false;
        }
        if (isNull(header)){
            header = {};
        }
        if (processData){
            data = obj2QueryStr(data);
        }
        else{
            data = JSON.stringify(data);
        }
        return dataParser(sender.post(url, obj2QueryStr(header), data));
    }
    return {
        get: get,
        post: post,
        loadDoc: function(url, header){
            if (isNull(header)){
                header = {};
            }
            var doc = sender.getDoc(url, obj2QueryStr(header));
            if (doc === null || doc === "null"){
                throw url+" not found";
            }
            return doc;
        }
    };
}
var StringReader = function(str){
    var Reader = loadClass("StringReader");
    var reader = new Reader(str);
    return {
        readLine: function( ) {
            return reader.readLine();
        },
        readLineTrim: function( allowSpaceLine ) {
            if (allowSpaceLine){
                var line = reader.readLine();
                if (line == null){
                    return line;
                }
                return line.trim();
            }
            var line = null;
            while ( (line = reader.readLine()) != null ){
                if (line.trim() != ""){
                    return line.trim();
                }
            }
            return null;
        },
        read: function(){
            return reader.read();
        }
    }
}